CP.FacebookService = function () {}

CP.FacebookService.prototype.checkLogin = function (callbackSuccess,callbackNotAuthorization,callbackNotLogin) {
	console.log('Check Login Facebook');
	FB.getLoginStatus(function(response) {
		console.log(response);
		if (response.status === 'connected') {
				// the user is logged in and has authenticated your
				// app, and response.authResponse supplies
				// the user's ID, a valid access token, a signed
				// request, and the time the access token 
				// and signed request each expire
				// var uid = response.authResponse.userID;
				// var accessToken = response.authResponse.accessToken;
				console.log(response);
				callbackSuccess(response);
			} else if (response.status === 'not_authorized') {
				// the user is logged in to Facebook, 
				// but has not authenticated your app
				console.log(response);
				callbackNotAuthorization(response)
			} else {
				// the user isn't logged in to Facebook.
				console.log(response);
				callbackNotLogin(response)
			}
	 });
}
CP.FacebookService.prototype.loginFacebook = function (callbackSuccess){
 	FB.login(function(){
 		if(callbackSuccess && typeof(callbackSuccess))
 			callbackSuccess();
 	},{scope: 'user_photos'});
}

CP.FacebookService.prototype.getAlbums = function (limit,paging,callbackSuccess,callbackError){
	var url = '/me/albums?limit='+limit;
	if(paging !='' && paging!= undefined)
		url += '&after='+paging;

	FB.api(
	    url,
	    function (response) {
	      if (response && !response.error) {
	        if(callbackSuccess && typeof(callbackSuccess))
	        	callbackSuccess(response);
	      }else{
	      	if(callbackError && typeof(callbackError))
	        	callbackError(response);
	      }
	    }
	);

}

CP.FacebookService.prototype.getImagesFromAlbums = function (albumId,limit,paging,callbackSuccess,callbackError){
	var url = albumId+'/photos?limit='+limit;
	if(paging !='' && paging!= undefined)
		url += '&pretty=0&after='+paging;

	FB.api(
	    url,
	    function (response) {
	      if (response && !response.error) {
	        if(callbackSuccess && typeof(callbackSuccess))
	        	callbackSuccess(response);
	      }else{
	      	if(callbackError && typeof(callbackError))
	        	callbackError(response);
	      }
	    }
	);

}